package com.zhu.transaction.utils;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSClientBuilder;
import com.zhu.transaction.pojo.OssProperties;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.InputStream;

/**
 * @author Zhu
 * @createtime 2020/12/6-10:11
 */
public class OssUtils {

    public static String uploadFile(InputStream fileInputStream, String path) {
        // 创建OSSClient实例。
        OSS ossClient = new OSSClientBuilder().build(OssProperties.END_POINT, OssProperties.ACCESS_KEY_ID, OssProperties.ACCESS_KEY_SECRET);

        ossClient.putObject(OssProperties.BUCKET_NAME, path, fileInputStream);

        // 关闭OSSClient。
        ossClient.shutdown();
        return "http://" + OssProperties.BUCKET_NAME + "." + OssProperties.END_POINT + "/" + path;
    }
}
